import axios from 'axios'

// 楼盘基本信息类型
export interface ProjectInfo {
  id: string | number
  title: string
  subtitle: string
  description: string
  buildingList: any[]
  totalCount: number
}

// API 响应基础类型
export interface ApiResponse<T = any> {
  code: number
  message: string
  data: T
}

/**
 * 获取当前楼盘信息
 * @param projectId
 * @returns
 */
export const getProjectInfo = async (projectId: string): Promise<ProjectInfo> => {
  try {
    const response = await axios.get<ApiResponse<ProjectInfo>>(
      `/api/project?project_id=${projectId}`
    )

    if (response.data.code === 200) {
      return response.data.data
    }

    throw new Error(response.data.message || '获取楼盘信息失败')
  } catch (error) {
    console.error('获取楼盘信息失败:', error)
    throw error
  }
}
